from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from database import Base


# 模型类对应数据库中的表
class Department(Base):
    __tablename__ = 'tb_dept'

    no = Column('dno', Integer, primary_key=True)
    name = Column('dname', String(10))
    location = Column('dloc', String(20))

    emps = relationship('Employee', backref='department')

    def __repr__(self):
        return self.name


class Employee(Base):
    __tablename__ = 'tb_emp'

    no = Column('eno', Integer, primary_key=True)
    name = Column('ename', String(20))
    job = Column(String(20))
    manager_id = Column('mgr', Integer, nullable=True)
    salary = Column('sal', Integer)
    comm = Column(Integer, nullable=True)
    department_id = Column('dno', Integer, ForeignKey('tb_dept.dno'))
